<template>
  <a-card>
    <div :class="advanced ? 'search' : null">
      <a-form layout="horizontal">
        <div :class="advanced ? null: 'fold'">
          <a-row >
          <a-col :md="8" :sm="24" >
            <a-form-item
              label="规则编号"
              :labelCol="{span: 5}"
              :wrapperCol="{span: 18, offset: 1}"
            >
              <a-input placeholder="请输入" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24" >
            <a-form-item
              label="使用状态"
              :labelCol="{span: 5}"
              :wrapperCol="{span: 18, offset: 1}"
            >
              <a-select placeholder="请选择">
                <a-select-option value="1">关闭</a-select-option>
                <a-select-option value="2">运行中</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24" >
            <a-form-item
              label="调用次数"
              :labelCol="{span: 5}"
              :wrapperCol="{span: 18, offset: 1}"
            >
              <a-input-number style="width: 100%" placeholder="请输入" />
            </a-form-item>
          </a-col>
        </a-row>
          <a-row v-if="advanced">
          <a-col :md="8" :sm="24" >
            <a-form-item
              label="更新日期"
              :labelCol="{span: 5}"
              :wrapperCol="{span: 18, offset: 1}"
            >
              <a-date-picker style="width: 100%" placeholder="请输入更新日期" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24" >
            <a-form-item
              label="使用状态"
              :labelCol="{span: 5}"
              :wrapperCol="{span: 18, offset: 1}"
            >
              <a-select placeholder="请选择">
                <a-select-option value="1">关闭</a-select-option>
                <a-select-option value="2">运行中</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
       
        </a-row>
        </div>
        <span style="float: right; margin-top: 3px;">
          <a-button type="primary">查询</a-button>
          <a-button style="margin-left: 8px">重置</a-button>
          <a @click="toggleAdvanced" style="margin-left: 8px">
            {{advanced ? '收起' : '展开'}}
            <a-icon :type="advanced ? 'up' : 'down'" />
          </a>
        </span>
      </a-form>
    </div>
    <div>
      <a-space class="operator">
        <a-button @click="addNew" type="primary">新建</a-button>
        <a-button >批量操作</a-button>
      </a-space>
      <standard-table
        :columns="columns"
        :dataSource="brandList"
        :rowKey="(record,index)=>{return index}"
        :bordered="true"
        @clear="onClear"
        @change="onChange"
        @selectedRowChange="onSelectChange"
      >
      
        <a-table
          slot="expandedRowRender"
          slot-scope="{record}"
          :rowKey="(record,index)=>{return index}"
          :columns="innerColumns"
          :border="true"
          :data-source="record.skuList"
          :pagination="false"
        ></a-table>
      
        <div slot="action" slot-scope="{ record}">
          <a style="margin-right: 8px">
            <a-icon type="plus"/>新增
          </a>
          <a style="margin-right: 8px">
            <a-icon type="edit"/>编辑
          </a>
         
          <router-link :to="`/list/query/detail/${record.key}`" >详情</router-link>
        </div>
        <template slot="statusTitle">
          <a-icon @click.native="onStatusTitleClick" type="info-circle" />
        </template>
      </standard-table>
    </div>
  </a-card>
</template>

<script>
import StandardTable from '@/components/table/StandardTable'
import { listSpu } from "@/services/spu";
const columns = [
  {
    title: '商品名称',
    dataIndex: 'name',
  },
  {
    title:'品牌名称',
    dataIndex: 'brandName',
    needTotal: true,
  },
  {
    title: '商品分类',
    dataIndex: 'categoryName',
  },
  {
    title: '原价',
    dataIndex: 'originPrice',
  },
  {
    title: '现价',
    dataIndex: 'price',
  },
  {
    title: '单位',
    dataIndex: 'unit',
  },
  {
    title: '操作',
    scopedSlots: { customRender: 'action' }
  }
]

const innerColumns = [
   {
    title: '商品编码',
    dataIndex: 'skuSn',
  },
  {
    title:'商品规格',
    dataIndex: 'name',
    needTotal: true,
  },
   {
    title:'图片',
    dataIndex: 'picUrl',
    needTotal: true,
  },
   {
    title:'现价',
    dataIndex: 'price',
    needTotal: true,
  },
   {
    title:'库存',
    dataIndex: 'stockNum',
    needTotal: true,
  },
]

const dataSource = []

export default {
  name: 'SpuList',
  components: {StandardTable},
  data () {
    return {
      advanced: true,
      columns: columns,
      innerColumns:innerColumns,
      dataSource: dataSource,
      brandList: [{name:"品牌"}],
      selectedRows: [],
      queryParams: {
      },
    }
  },
  authorize: {
    deleteRecord: 'delete'
  },
  created(){
    this.getList();
  },
  methods: {

     getList() {
    
      listSpu(this.queryParams).then(response => {
        console.log("获取品牌数据的啦",response.data);
        this.brandList =  response.data.data.list;
      });
    },

    deleteRecord(key) {
      this.dataSource = this.dataSource.filter(item => item.key !== key)
      this.selectedRows = this.selectedRows.filter(item => item.key !== key)
    },
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    remove () {
      this.dataSource = this.dataSource.filter(item => this.selectedRows.findIndex(row => row.key === item.key) === -1)
      this.selectedRows = []
    },
    onClear() {
      this.$message.info('您清空了勾选的所有行')
    },
    onStatusTitleClick() {
      this.$message.info('你点击了状态栏表头')
    },
    onChange() {
      this.$message.info('表格状态改变了')
    },
    onSelectChange() {
      this.$message.info('选中行改变了')
    },
    addNew () {
      this.dataSource.unshift({
        key: this.dataSource.length,
        no: 'NO ' + this.dataSource.length,
        description: '这是一段描述',
        callNo: Math.floor(Math.random() * 1000),
        status: Math.floor(Math.random() * 10) % 4,
        updatedAt: '2018-07-26'
      })
    },
    handleMenuClick (e) {
      if (e.key === 'delete') {
        this.remove()
      }
    }
  }
}
</script>

<style lang="less" scoped>
  .search{
    margin-bottom: 54px;
  }
  .fold{
    width: calc(100% - 216px);
    display: inline-block
  }
  .operator{
    margin-bottom: 18px;
  }
  @media screen and (max-width: 900px) {
    .fold {
      width: 100%;
    }
  }
</style>
